import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

// 确保组件路径正确，且组件是Vue组件
import RootPage from '../view/index/RootPage.vue'
import DeskTop from '../view/index/DeskTop.vue'
// import LoginPage from '../view/LoginPage.vue'

import Tool from '../global'

import JobManager from '../view/admin/job/JobManager.vue'
import DbsetManager from '../view/admin/dbset/DbsetManager.vue'
import LogManager from '../view/admin/Log/LogManager.vue'
import DictionaryComparison from '../view/admin/dict/DictionaryComparison.vue'
import DictManager from '../view/admin/dict/DictManager.vue'

// 明确指定路由类型为RouteRecordRaw数组
const routes: RouteRecordRaw[] = [
    {
        path: "/", 
        component: RootPage, 
        redirect: "/job",
        children: [
            // { 
            //     name: "workbench", 
            //     path: "desktop", 
            //     component: DeskTop,
            //     meta: { title: "工作台" } 
            // },
            { 
                name: "jobManager", 
                path: "job", 
                component: JobManager,
                meta: { title: "任务信息" } 
            },
            { 
                name: "dbsetManager", 
                path: "dbset", 
                component: DbsetManager,
                meta: { title: "数据库连接信息" } 
            },
            { 
                name: "logManager", 
                path: "log", 
                component: LogManager,
                meta: { title: "日志查询" } 
            },
            {
                name: "dictionary",
                path: "dict",
                meta: { title: "字典对照" },
                children: [
                    // { 
                    //     name: "dictManager", 
                    //     path: "fwt", 
                    //     component: DictManager,
                    //     meta: { title: "字典对照1" }
                    // },
                    { 
                        name: "dictionaryComparison", 
                        path: "fwtgzl", 
                        component: DictionaryComparison,
                        meta: { title: "字典对照2" }
                    }
                ]
            }
        ]
    }
    // { 
    //     path: "/login", 
    //     component: LoginPage, 
    //     name: "login",
    //     meta: { title: "登录" } 
    // }
]

const toolObj = new Tool()

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    // 可以添加页面标题设置
    if (to.meta.title) {
        document.title = to.meta.title as string
    }
    next()
})

export default router;
    